package com.taiyuan.zfmvp.shejimoshi.single.type5;

/**
 * @param 
 * @Author: zhoufang@si-tech.com.cn
 * @Descriiption:  双重检查
 * @Date 2022/10/3
 * @return
 */
public class SingletonTest05 {
    public static void main(String[] args) {
        Singelton singelton = Singelton.getInstance();
        Singelton singelton2 = Singelton.getInstance();
        System.out.println(singelton == singelton2);
    }
}

class  Singelton{

    private   static  volatile Singelton instance;

    private Singelton(){

    }

    //当使用该方法再去创建  即懒汉式 加入双重检查
    public static  Singelton getInstance(){

        if(instance == null){
            synchronized (Singelton.class){
                if(instance == null){
                    instance = new Singelton();
                }
            }


        }
        return  instance;
    }

}
